<template>
  <q-page class="cc-admin">
    <div>
      <q-table
        flat
        color="primary"
        class="cross_table"
        separator="cell"
        :columns="columns"
        :data="list"
        row-key="id"
        :pagination.sync="pagination"
        :visible-columns="group"
        @request="query"
        :rows-per-page-options="[10,20,50,100]"
        :loading="loading"
        :selection="mobile?'none':'multiple'"
        :selected.sync="selected"
      >
        <template v-slot:top="table">
          <div class="row no-wrap full-width">
            <q-input
              clearable
              outlined
              dense
              placeholder="请输入关键字搜索"
              class="on-left"
              @input="query"
              debounce="500"
              v-model="key"
            >
              <template #append>
                <q-btn
                  flat
                  round
                  icon="search"
                  color="primary"
                  @click="query"
                  :loading="loading"
                >
                  <q-tooltip>搜索</q-tooltip>
                </q-btn>
              </template>
            </q-input>
            <q-space />
          <table-top-btns
              label="定时任务"
              modelName="task"
              :showAdd="true"
              :showImport="false"
              :showExport="false"
              :showDeleteBatch="true"
              :showGroup="true"
              :showFull="true"
              :table="table"
              :selected="selected"
              :importing="importing"
              :exporting="exporting"
              :importExcelUrlFull="importExcelUrlFull"
              :columns="columns"
              @groupChange="groupChange"
              @add="add"
              @importExcel="importExcel"
              @exportExcel="exportExcel"
              @showConfirm="showConfirm"
            />
          </div>
        </template>
        <template #body-cell-status="props">
          <q-td
            key="status"
            :props="props"
          >
            {{getDictLabel(quartzStatus,props.row.status) }}
          </q-td>
        </template>
        <template #body-cell-opt="props">
          <q-td
            :props="props"
            width="120"
          >
              <cc-btn label="编辑"  color="primary" icon="edit"  @click="edit(props.row)"> <q-tooltip>编辑</q-tooltip></cc-btn>
            <btn-del
              label=""
              @confirm="del(props.row)"
            />
          </q-td>
        </template>
      </q-table>
    </div>
    <cc-dialog ref="dialog" @submit="submit" :title="`${editType}`">

            <div class="col-12">
              <h5>
                <q-icon
                  name="star"
                  color="red"
                /> 任务类名：</h5>
              <q-input
                outlined
                dense
                v-model="form.jobClassName"
                type="text"
                clearable
                :rules="[requiredTest]"
              />
            </div>
            <div class="col-12">
              <h5>
                <q-icon
                  name="star"
                  color="red"
                /> cron表达式：</h5>
              <q-input
                outlined
                dense
                v-model="form.cronExpression"
                type="text"
                clearable
                :rules="[requiredTest]"
              />
            </div>
            <div class="col-12">
              <h5> 参数：</h5>
              <q-input
                outlined
                dense
                v-model="form.parameter"
                type="text"
                clearable
              />
            </div>
            <div class="col-12">
              <h5> 描述：</h5>
              <q-input
                outlined
                dense
                v-model="form.description"
                type="text"
                clearable
              />
            </div>
            <div class="col-12">
              <h5>
                <q-icon
                  name="star"
                  color="red"
                /> 状态：</h5>
              <q-select
                outlined
                dense
                emit-value
                v-model="form.status"
                map-options
                :options="quartzStatus"
                clearable
              />
            </div>
        </cc-dialog>
    <confirm
      ref="confirmDialog"
      :msg="confirmMsg"
      @confirm="deleteBatch()"
    />
  </q-page>
</template>

<script>
import { IndexMixin } from 'boot/mixins';
import { getDictLabel } from 'boot/dictionary';
import confirm from 'components/confirm';
import { requiredTest } from 'boot/inputTest';

export default {
  name: 'SysQuartzJob',
  mixins: [IndexMixin],
  components: {
    confirm,
  },
  data() {
    return {
      columns: [
        {
          name: 'index',
          align: 'center',
          label: '序号',
          field: 'index',
          headerClasses: 'cc-table-index',
        },
        {
          name: 'jobClassName', align: 'center', label: '任务类名', field: 'jobClassName',
        },
        {
          name: 'cronExpression', align: 'center', label: 'cron表达式', field: 'cronExpression',
        },
        {
          name: 'parameter', align: 'center', label: '参数', field: 'parameter',
        },
        {
          name: 'description', align: 'center', label: '描述', field: 'description',
        },
        {
          name: 'status', align: 'center', label: '状态', field: 'status',
        },
        {
          name: 'opt', align: 'center', label: '操作', field: 'opt',
        },
      ],
      quartzStatus: [{ value: -1, label: '停止' }, { value: 0, label: '正常' }],
      url: {
        list: '/sys/quartzJob/list',
        add: '/sys/quartzJob/add',
        edit: '/sys/quartzJob/edit',
        delete: '/sys/quartzJob/delete',
        deleteBatch: '/sys/quartzJob/deleteBatch',
        exportXlsUrl: '/sys/quartzJob/exportXls',
        importExcelUrl: '/sys/quartzJob/importExcel',
      },
    };
  },
  methods: {
    requiredTest,
    getDictLabel,
    initDict() {
    },
  },
  mounted() {
    this.initDict();
  },
};
</script>

<style lang="stylus"></style>
